#include "CAF.h"

CAF::CAF(float x_mi, float x_ma, float y_mi, float y_ma, float z_mi, float z_ma, int st, float vi, int tn, float df, float ds, float foo, bool bf){

    x_min = x_mi;
    x_max = x_ma;
    y_min = y_mi;
    y_max = y_ma;
    z_min = z_mi;
    z_max = z_ma;
    x = rand()/ double(RAND_MAX) *x_max + x_min;
    y = rand()/ double(RAND_MAX) *y_max + y_min;
    z = rand()/ double(RAND_MAX) *z_max + z_min;
    step = st;
    visual = vi;
    try_num = tn;
    delta = df;
    delta_s = ds;
    food =foo;
    best_flag = bf;
}

void CAF::move(float r_step, float r_angle, float z_angle){

    float x_tmp = x;
    float y_tmp = y;
    float z_tmp = z;
    x += (r_step* cos(z_angle)*cos(r_angle));
    y += (r_step* cos(z_angle)*sin(r_angle));
    z += (r_step* sin(z_angle));
    if(x<x_min || x>x_max || y<y_min || y>y_max || z>z_max || z<z_min) {
        x = x_tmp;
        y = y_tmp;
        z = z_tmp;
    }
}

void CAF::move(){

    float r_angle = rand()/ double(RAND_MAX) *2 *3.1415;
    float z_angle = rand()/ double(RAND_MAX) *3.1415;
    float r_step = rand()/ double(RAND_MAX) *step;
    float x_tmp = x;
    float y_tmp = y;
    float z_tmp = z;

    x += (r_step* cos(z_angle)*cos(r_angle));
    y += (r_step* cos(z_angle)*sin(r_angle));
    z += (r_step* sin(z_angle));
    if(x<x_min || x>x_max || y<y_min || y>y_max || z>z_max || z<z_min) {
        x = x_tmp;
        y = y_tmp;
        z = z_tmp;
    }

}

void CAF::move(float x_n, float y_n, float z_n, bool direct){

    float x_tmp = x;
    float y_tmp = y;
    float z_tmp = z;
    x = x_n;
    y = y_n;
    z = z_n;
    if(x<x_min || x>x_max || y<y_min || y>y_max || z>z_max || z<z_min) {
        x = x_tmp;
        y = y_tmp;
        z = z_tmp;
    }

}
